<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
        }
        
        div {
            height: 100px;
            width: 100px;
            background-color: green;
            position: absolute;
        }
    </style>
</head>

<body>
    <div></div>
</body>
<script>
    //x y 手指刚触摸屏幕的位置
    var x = 0;
    var y = 0;
    // 盒子的初始位置
    var boxLeft = 0;
    var boxTop = 0;
    var div = document.querySelector('div');
    div.addEventListener('touchstart', function(e) {
        console.log(e);
        //x y 手指刚触摸屏幕的位置
        x = e.touches[0].pageX;
        y = e.touches[0].pageY;
        //手指一点盒子获取盒子的位置
        boxLeft = this.offsetLeft
        boxTop = this.offsetTop
    })
    div.addEventListener('touchmove', function(e) {
        //要移动的主轴的位置 e.touches[0].pageX 手指移动的最后一次位置
        var boxmoveX = e.touches[0].pageX - x;
        //要移动的副轴的位置
        var boxmoveY = e.touches[0].pageY - y;
        var ax = boxLeft + boxmove;
        var ay = boxTop + boxmoveY;
        this.style.left = ax + "px";
        this.style.top = ay + "px";
    })
</script>

</html>